// ==UserScript==
// @name           Tennaxia Trac: Worked Hours
// @namespace      www.tennaxia.net
// @include        https://*.tennaxia.net/t3_trac/report/35*
// @include        https://*.tennaxia.net/t3_trac/report/39*
// ==/UserScript==

function getSwitchLink() {
	var link = document.createElement('span');
	var url = document.location.href;
	if(url.search('39') != -1) {
		link.innerHTML = ' | <a href="'+url.replace('39', '35')+'">by ticket</a>';
	} else if(url.search('35') != -1) {
		link.innerHTML = ' | <a href="'+url.replace('35', '39')+'">by day</a>';
	}
	return link;
}

function addSwitchLink() {
	var h2 = document.getElementsByTagName('h2');
	h2[1].parentNode.insertBefore(getSwitchLink(), h2[1]);
}

function addReport35Links() {
	var content = document.getElementById('content');
	if(content) {
		content.innerHTML = content.innerHTML.replace(/(\d\d)\/(\d\d)\/(\d\d\d\d)/g,
		'<a href="https://www.tennaxia.net/t3_trac/report/35?DATESTART=$3-$2-$1&DATEEND=$3-$2-$1&MINE">$1\/$2\/$3</a>');
	}
}

new function () {
	addSwitchLink();
	addReport35Links();
}